package br.com.aquinoevasconcelos.servlets.contato;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.fachada.Fachada;

/**
 * Servlet implementation class VerContato
 */
@WebServlet("/VerContato")
public class VerContato extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public VerContato() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Fachada fachada = Fachada.getInstancia();

		String codigo = request.getParameter("id");
		long id = Long.parseLong(codigo);

		try {

			request.setAttribute("verContato", fachada.editarContato(id));

			request.getRequestDispatcher("admin/ver_contato.jsp").forward(
					request, response);

		} catch (Exception e) {
			response.sendRedirect("pagina_erro/erro.jsp");
		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);

	}

}
